/*
 * @lc app=leetcode.cn id=806 lang=typescript
 *
 * [806] 写字符串需要的行数
 */

// @lc code=start
function numberOfLines(widths: number[], s: string): number[] {
    return s
        .split("")
        .map((i) => {
            return widths[i.charCodeAt(0) - 97];
        })
        .reduce(
            ([row, total], cur) => {
                if (total + cur > 100) {
                    return [row + 1, cur];
                }
                return [row, total + cur];
            },
            [1, 0]
        );
}
// @lc code=end
